package com.woniu.idearbac.Controller;

import com.woniu.idearbac.Service.PermissionService;
import com.woniu.idearbac.dto.PerDTO;
import com.woniu.idearbac.util.Result;
import com.woniu.idearbac.vo.TreeNode;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 功能描述
 *
 * @author PC
 * @date -2022/11/30-时间-19:03
 * @product idea-rbac
 */
@RestController
@RequestMapping("/permissions")
public class PermissionsController {
    @Resource
    private PermissionService permissionService;
    @GetMapping("{rid}")
    public Result selAll(@PathVariable Integer rid){
        List<TreeNode> nodes = permissionService.selectAllPer(0);
        List<Integer> list = permissionService.selectPerByRid(rid);
        return Result.ok().data("permissionList",nodes).data("defaultChecked",list);
    }
    @PostMapping("")
    public Result update(@RequestBody PerDTO perDTO){
        int add = permissionService.add(perDTO);
        if(add > 0){
            return Result.ok();
        }else{
            return Result.error();
        }
    }
}
